package se.webbzon.boltzmann.editor.list;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JList;
import javax.swing.ListCellRenderer;

import se.webbzon.boltzmann.editor.factory.worldobject.WorldObjectFactory;

public class FactoryListCell extends EditorListCell implements ListCellRenderer<WorldObjectFactory> {
	
	// Auto generated serial version UID
	private static final long serialVersionUID = -1986809453113429849L;
	
	// The world object factory associated with this list cell
	private WorldObjectFactory factory;
	
	/*============================================================
	Constructors
	============================================================*/
	
	public FactoryListCell() {
		super(new Dimension(128,20));
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	@Override public void paintComponent(Graphics g) {
		super.paintComponent(g);
		g.setFont(getFont());
		g.drawString(factory.getName(), 2, 16);
	}

	@Override public Component getListCellRendererComponent(
			JList<? extends WorldObjectFactory> list, WorldObjectFactory factory,
			int index, boolean isSelected, boolean cellHasFocus) {
		setSelected(isSelected);
		this.factory = factory;
		return this;
	}

}
